package com.moxing.admin.common.dto;


import lombok.Data;

import java.util.UUID;

@Data
public final class RestResponseDTO<T> implements java.io.Serializable{

    private int status = 1;
    private String timestamp;
    private String requestId;
    private String message;
    private String errorCode;
    private T resultBody;

    public static <T> RestResponseDTO<T> success() {
        RestResponseDTO<T> response = new RestResponseDTO<T>();
        response.setStatus(1);
        response.setRequestId(UUID.randomUUID().toString());
        return new RestResponseDTO<T>();
    }

    public static <T> RestResponseDTO<T> success(T result) {
        RestResponseDTO<T> response = new RestResponseDTO<T>();
        response.setStatus(1);
        response.setRequestId(UUID.randomUUID().toString());
        response.setResultBody(result);
        return response;
    }

    public static <T> RestResponseDTO<T> success(String message,T result) {
        RestResponseDTO<T> response = new RestResponseDTO<T>();
        response.setStatus(1);
        response.setRequestId(UUID.randomUUID().toString());
        response.setResultBody(result);
        response.setMessage(message);
        return response;
    }

    public static <T> RestResponseDTO<T> validFail(String msg) {
        RestResponseDTO<T> response = new RestResponseDTO<T>();
        response.setMessage(msg);
        response.setStatus(-1);
        response.setRequestId(UUID.randomUUID().toString());
        return response;
    }

}
